using System.Collections;
using System.Data.Linq;

namespace Magiq.Sql {
    public class MagiqToSqlOperationsProvider {
        private const string DataQueryAssemblyQualifiedName =
            "System.Data.Linq.DataQuery`1, System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

        public bool Handles(IEnumerable source) {
            var type = source.GetType();
            if (!type.IsGenericType)
                return false;

            var genericType = type.GetGenericTypeDefinition();
            return genericType.AssemblyQualifiedName == DataQueryAssemblyQualifiedName ||
                   genericType == typeof(Table<>) || genericType == typeof(EntitySet<>);
        }
    }
}